package wangshuai.risk.algorithm;

import java.util.List;

import publics.model.Ratio;

public class RatioAnalyse {
	/**
	 * 根据 财务比率分析表 分析 各指标 ，并且 返回 分析结果
	 * @param ratio  要分析的财务比率表
	 * @return   分析结果
	 */
	public String ratioAnalyse(Ratio  ratio){
		String rResult;
		boolean marke = false;//标志每个阶段是否有异常情况
		
		//短期偿债能力分析
		rResult = "<b>"+ratio.getYear()+"年财务比率情况<br></b>"+"<b>1.短期偿债能力: <br></b>";
		if(ratio.getCurrent()!= null){
			if(ratio.getCurrent() > 1000 || ratio.getCurrent() < 0){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 流动比率:<font color=\"red\">"+ratio.getCurrent()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getCurrent()< 100){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 流动比率:<font color=\"red\">"+ratio.getCurrent()+"%</font> 值太低；<br>";
				marke = true;
			}
		}
		if(ratio.getCurrent2()!= null){
			if(ratio.getCurrent2() > 1000 || ratio.getCurrent2() < 0){
				rResult += "&nbsp;"+ ratio.getYear() +"年 流动比率:<font color=\"red\">"+ratio.getCurrent2()+"% 值异常</font>；<br>";
				marke = true;
			}else if(ratio.getCurrent2()< 100){
				rResult +="&nbsp;"+ ratio.getYear() +"年 流动比率:<font color=\"red\">"+ratio.getCurrent2()+"%</font> 值太低；<br>";
				marke = true;
			}
		}
		
		if(ratio.getQuick()!= null){
			if (ratio.getQuick() > 500 || ratio.getCurrent2() < 0) {
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 速动比率:<font color=\"red\">"+ratio.getQuick()+"% 值异常</font>；<br>";
				marke = true;
			}else if (ratio.getQuick() < 100) {
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 速动比率:<font color=\"red\">"+ratio.getQuick()+"%</font> 值太低；<br>";
				marke = true;
			}
		}
		if(ratio.getQuick2()!= null){
			if (ratio.getQuick2() > 500 || ratio.getCurrent2() < 0) {
				rResult += "&nbsp;"+ ratio.getYear() +"年 速动比率:<font color=\"red\">"+ratio.getQuick2()+"% 值异常</font>；<br>";
				marke = true;
			}else if (ratio.getQuick2() < 100) {
				rResult += "&nbsp;"+ ratio.getYear() +"年 速动比率:<font color=\"red\">"+ratio.getQuick2()+"%</font> 值太低；<br>";
				marke = true;
			} 
		}
		/*if(ratio.getCashDebt()){
			rResult += ratio.getYear()-1 +"年 现金流动负债比  "+ratio.getCashDebt()+"% 值太低；";
			marke = true;
		}
		if(ratio.getCashDebt2()){
			rResult += ratio.getYear() +"年 现金流动负债比  "+ratio.getCashDebt2()+"% 值太低；";
			marke = true;
		}*/
		//未完成，待补充。
		
		if(!marke){
			rResult += "正常。<br>";
		}
		marke = false;
		//短期负债能力分析完毕
		
		//长期偿债能力分析开始
		rResult += "<b>2.长期偿债能力: <br></b>";
		if(ratio.getLiab()!= null){
			if(ratio.getLiab() > 500 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 资产负债率 :<font color=\"red\">"+ratio.getLiab()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getLiab() > 65){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 资产负债率 :<font color=\"red\">"+ratio.getLiab()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getLiab2()!= null){
			if(ratio.getLiab() > 500 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ ratio.getYear() +"年 资产负债率 :<font color=\"red\">"+ratio.getLiab2()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getLiab2()> 65){
				rResult += "&nbsp;"+ ratio.getYear() +"年 资产负债率 :<font color=\"red\">"+ratio.getLiab2()+"%</font> 太高，有风险；<br>";
				marke = true;
			} 
		}
		if(ratio.getEquity()!= null){
			if(ratio.getEquity() > 300 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 产权比率:<font color=\"red\">"+ratio.getEquity()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getEquity() > 65){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 产权比率:<font color=\"red\">"+ratio.getEquity()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getEquity2()!= null){
			if(ratio.getEquity2() > 300 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ ratio.getYear() +"年 产权比率:<font color=\"red\">"+ratio.getEquity2()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getEquity2() > 65){
				rResult += "&nbsp;"+ ratio.getYear() +"年 产权比率:<font color=\"red\">"+ratio.getEquity2()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getContingentLiab()!= null){
			if(ratio.getContingentLiab() > 300 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 或有负债比率:<font color=\"red\">"+ratio.getContingentLiab()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getContingentLiab() > 65){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 或有负债比率:<font color=\"red\">"+ratio.getContingentLiab()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getContingentLiab2()!= null){
			if(ratio.getContingentLiab2() > 300 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ ratio.getYear() +"年 或有负债比率:<font color=\"red\">"+ratio.getContingentLiab2()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getContingentLiab2() > 65){
				rResult += "&nbsp;"+ ratio.getYear() +"年 或有负债比率:<font color=\"red\">"+ratio.getContingentLiab2()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getInterestTimes()!= null){
			if(ratio.getInterestTimes() > 20 || ratio.getLiab() < -5){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 已获利息倍数:<font color=\"red\">"+ratio.getInterestTimes()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getInterestTimes() < 1){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年已获利息倍数:<font color=\"red\">"+ratio.getInterestTimes()+"%</font> 太低，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getInterestTimes2()!= null){
			if(ratio.getInterestTimes2() > 20 || ratio.getLiab() < -5){
				rResult += "&nbsp;"+ ratio.getYear() +"年 已获利息倍数:<font color=\"red\">"+ratio.getInterestTimes2()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getInterestTimes2() < 1){ 
				rResult += "&nbsp;"+ ratio.getYear() +"年 已获利息倍数:<font color=\"red\">"+ratio.getInterestTimes2()+"%</font> 太低，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getInterestLiab()!= null){
			if(ratio.getInterestLiab() > 100 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 带息负债比率:<font color=\"red\">"+ratio.getInterestLiab()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getInterestLiab() > 70){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 带息负债比率:<font color=\"red\">"+ratio.getInterestLiab()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getInterestLiab2()!= null){
			if(ratio.getInterestLiab2() > 100 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ ratio.getYear() +"年 带息负债比率:<font color=\"red\">"+ratio.getInterestLiab2()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getInterestLiab2() > 70){
				rResult += "&nbsp;"+ ratio.getYear() +"年 带息负债比率:<font color=\"red\">"+ratio.getInterestLiab2()+"%</font> 太高，有风险；<br>";
				marke = true;
			}
		}
		
		if(!marke){
			rResult += "正常。<br>";
		}
		marke = false;
		//长期偿债能力分析结束
		
		//运营能力分析开始
		rResult += "<b>3.运营能力: <br></b>";
		if(ratio.getRecTur()!= null){
			if(ratio.getRecTur() > 30000 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 应收账款周转率:<font color=\"red\">"+ratio.getRecTur()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getRecTur() < 100){
				rResult += "&nbsp;"+ (ratio.getYear()-1) +"年 应收账款周转率:<font color=\"red\">"+ratio.getRecTur()+"%</font> 太低，有风险；<br>";
				marke = true;
			}
		}
		if(ratio.getRecTur()!= null){
			if(ratio.getRecTur2() > 30000 || ratio.getLiab() < 0){
				rResult += "&nbsp;"+ ratio.getYear() +"年 应收账款周转率:<font color=\"red\">"+ratio.getRecTur2()+"% 值异常</font>；<br>";
				marke = true;
			}else if( ratio.getRecTur2() < 100){
				rResult += "&nbsp;"+ ratio.getYear() +"年 应收账款周转率:<font color=\"red\">"+ratio.getRecTur2()+"%</font> 太低，有风险；<br>";
				marke = true;
			}
		}
		
		if(!marke){
			rResult += "正常。<br>";
		}
		marke = false;
		//运营能力分析结束
		
		//***获利能力分析开始
		rResult += "<b>4.获利能力: <br></b>";
		
		
		
		if(!marke){
			rResult += "正常。<br>";
		}
		marke = false;
		//获利能力分析结束
		
		//***发展能力分析开始
		rResult += "<b>5.发展能力: <br></b>";
		
		
		
		if(!marke){
			rResult += "正常。<br>";
		}
		marke = false;
		//发展能力分析结束
		
		
		//***其他比率分析开始
		rResult += "<b>6.其他比率: <br></b>";
		
		//添加分析代码
		
		if(!marke){
			rResult += "正常。<br>";
		}
		marke = false;
		//其他比率分析结束
		
		
		rResult += "<br>";
		System.out.println("rResult="+rResult);
		
		return rResult;	
	}

}
